package com.wsoft.system.controller;

import com.wsoft.constant.RedisKeyConstant;
import com.wsoft.core.annotation.GetRedisCache;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.SysMenuDto;
import com.wsoft.system.dto.SysMenuNode;
import com.wsoft.system.service.ISysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author kyle
 * @since 2024年09月02日 09:04:57
 */
@RestController
@Tag(name = "菜单")
@RequestMapping("/sys/menu")
public class SysMenuController {

    @Resource
    private ISysMenuService sysMenuService;
    @Operation(summary = "新增菜单",description = "新增菜单")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid SysMenuDto dto) {
        boolean b = sysMenuService.insert(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑菜单",description = "编辑菜单")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid SysMenuDto dto) {
        boolean b = sysMenuService.update(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除菜单",description = "删除数据")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = sysMenuService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "查看菜单详情",description = "查看菜单详情")
    @GetMapping("/get")
    public ResponseResult getMenu(@RequestParam("id") Long id) {
        return ResponseResult.success(sysMenuService.getMenu(id));
    }

    @Operation(summary = "菜单列表(分页)",description = "分页")
    @PostMapping("/list")
    public ResponseResult pageList(@RequestBody @Valid SysMenuDto dto) {
        return ResponseResult.success(ResponsePage.restPage(sysMenuService.pageMenu(dto)));
    }

    @Operation(summary = "树形结构返回所有菜单列表",description = "树形结构返回所有菜单列表")
    @GetMapping(value = "/treeList")
    public ResponseResult<List<SysMenuNode>> treeList() {
        List<SysMenuNode> list = sysMenuService.treeList();
        return ResponseResult.success(list);
    }
}
